def isPrime(p):
    if a == 1: return False
    test = True
    w = a - 1
    while w > 1:
        if not a % w:
            test = False
            break
        w -= 1
    return test


k = input()
o = []
for g in range(len(k) + 1):
    for w in range(g, len(k) + 1):
        if g == w:
            continue
        a = int(k[g:w])
        if isPrime(a):
            o += [a]
print(max(o)if o else 0)




